<template>
  <div class="jianDingList-page">
    <Menus title="鉴定机构查询">
      <a @click="backtolist" href="javascript:void(0)" v-if="detail">
        <div class="img_block">
          <img class="img_margin" src="static/img/icon_fanhui.png" alt="返回">
        </div>
        <span>返回</span>
      </a>
      <a @click="$router.go(-1)" href="javascript:void(0)" v-if="!detail">
        <div class="img_block">
          <img class="img_margin" src="static/img/icon_fanhui.png" alt="返回">
        </div>
        <span>返回</span>
      </a>
      <router-link to="/">
        <div class="img_block">
          <img class="img_margin" src="static/img/icon_fanhuishouye.png" alt="返回首页">
        </div>
        <span>返回首页</span>
      </router-link>
    </Menus>
    <template v-if="!detail">
      <div class="jianding-list-head">
        <div class="content">
          <h1>{{type}}</h1>
          <div class="intro">
            <strong>{{currentarea}}</strong>
            <p> 共
              <span>{{currentjdofficelist.length}}</span> 家机构</p>
          </div>
          <a href="javascript:void(0)" @click="show_select_areacode = true" class="btn btn-default btn-lg btn-success">查询其它州市机构</a>
        </div>
      </div>
      <div class="jianding-list">
        <div class="lists">
          <div class="item" v-for="(item, index) in currentjdofficelist" :key="'key-'+index">
            <div class="content" @click="getEmployeelist(item)">
              <div class="name">{{ item.name }}</div>
              <ul>
                <li>
                  <label>简介：</label>
                  <div class="ct">{{ item.desc }}
                  </div>
                </li>
                <li>
                  <label>地址：</label>
                  <div>{{ item.address }}</div>
                </li>
                <li>
                  <label>电话：</label>
                  <div>{{ item.tell }}</div>
                </li>
              </ul>
            </div>
          </div>

        </div>

        <div class="btns">
          <p>如果想要查询其他州市 办理“{{ type }}”的机构，请点击</p>
          <a href="#" @click="show_select_areacode = true" class="btn btn-default btn-lg">查询其它州市机构</a>
        </div>

      </div>
    </template>
    <!-- 详情开始 -->
    <div class="jianding-detail" v-show="detail">
      <h1 class="name">
        {{ jdoffice.name }}
      </h1>
      <div class="contact">
        {{ jdoffice.address }}<br> 电话：{{ jdoffice.tell }}
      </div>
      <div class="intro">
        <div class="ht"><img src="static/img/icon/jianding/circle.png"> 机构简介</div>
        <div class="content">
          <p>{{ jdoffice.desc }}</p>
        </div>
      </div>
      <div class="map">
        <div class="ht"><img src="static/img/icon/jianding/circle.png"> 机构地图</div>
        <div class="content">
          <div id="jd-map-container"></div>
        </div>
      </div>
      <div class="ry">
        <div class="ht"><img src="static/img/icon/jianding/circle.png"> 机构人员</div>
        <ul>
          <li v-for="(item, index) in employeelist" :key="'key-' + index">
            <a href="javascript:void(0)" @click="getPersonnel(item)" class="btn btn-default">{{ item.name }}</a>
          </li>
        </ul>
      </div>
    </div>
    <!-- 详情结束 -->
    <div class="select_area" v-if="show_select_areacode">
      <div class="wrap">
        <div class="ht">请选择地区</div>
        <a href="javascript:void(0)" class="closed" @click="show_select_areacode=false"><img src="static/img/icon_close.png" alt=""></a>
        <div class="content">
          <a v-for="(item,key) in $root.area" :key="'key-'+key" @click="changeArea(key)">
            <span>{{item.name}}</span>
          </a>
        </div>
      </div>
      <div class="mask" @click="show_select_areacode=false"></div>
    </div>
    <Dialogs v-model="dialog" />
  </div>
</template>
<script>
import Menus from '../components/Menu'
import api from '../datas/api'
import Dialogs from '../components/Dialog'
import TMap from '../functions/map'
export default {
  name: 'JDList',
  components: {
    Menus,
    Dialogs
  },
  data() {
    return {
      type: '',
      currentarea: '',
      currentareacode: 0,
      currentjdofficelist: [],
      show_select_areacode: false,
      detail: false,
      dialog: {
        maskClose: true,
        show: false,
        title: '叶攀',
        cancelBtn: '返回',
        content:
          '编号：530101001028<br> 技术职称：实验师<br> 行业资格：执业教师<br> 执业类别：法医物证鉴定；法医临床鉴定。'
      },
      jdoffice: {},
      employeelist: []
    }
  },
  mounted() {
    this.type = this.$route.params.type
    this.currentarea = this.$root.config.web_area
    this.currentareacode = this.$root.config.web_code
    this.getJdoffice()
  },
  methods: {
    backtolist() {
      if (this.detail) {
        this.detail = false
      }
    },
    async getJdoffice() {
      this.$loading.show()
      let data = await this.$get(
        api.jiandingoffice + this.currentareacode + '&molds=' + this.type
      )
      this.currentjdofficelist = data.result.data
      this.$loading.hide()
    },
    changeArea(code) {
      this.currentarea = this.$root.area[code].alias
      this.currentareacode = code
      this.getJdoffice()
      this.show_select_areacode = false
    },
    async getEmployeelist(item) {
      let data = await this.$get(api.jiandingemployee + item.id)
      this.employeelist = data.items
      console.log(data)
      this.jdoffice = item
      this.detail = true
      this.getMap()
    },
    getPersonnel(employee) {
      this.dialog.show = true
      this.dialog.title = employee.name
      this.dialog.content =
        '编号：' +
        employee.no +
        '技术职称：' +
        employee.title +
        '<br> 行业资格：' +
        employee.qualification +
        '<br> 执业类别：' +
        employee.industry_type
    },
    async getMap() {
      const dom = document.querySelector('#jd-map-container')
      if (dom.childNodes.length) {
        dom.childNodes[0].remove()
      }

      // 在此完成该函数
      const qq = await TMap('OB4BZ-D4W3U-B7VVO-4PJWW-6TKDJ-WPB77')
      const map = new qq.maps.Map(dom, {
        center: new qq.maps.LatLng(
          this.jdoffice.geography.split(',')[0],
          this.jdoffice.geography.split(',')[1]
        ),
        zoom: 17
      })
      // 地图点信息
      const infoWin = new qq.maps.InfoWindow({ map, zIndex: 10000 })
      const position = new qq.maps.LatLng(
        this.jdoffice.geography.split(',')[0],
        this.jdoffice.geography.split(',')[1]
      )
      const anchor = new qq.maps.Point(24, 50)
      const size = new qq.maps.Size(100, 100)
      const origin = new qq.maps.Point(0, 0)
      const scaleSize = new qq.maps.Size(48, 48)
      const icon = new qq.maps.MarkerImage(
        'static/img/icon/position.png',
        size,
        origin,
        anchor,
        scaleSize
      )
      // 添加marker
      const marker = new qq.maps.Marker({
        position,
        map,
        animation: qq.maps.MarkerAnimation.DOWN
      })
      // const infotmp = this.setMapContent(masData[i])
      // 加载marker图标
      marker.setIcon(icon)

      infoWin.open()
      infoWin.setContent(`<div class="map-marker-info" style="padding:0 0 10px;">
          <h2 style="font-size:18px; margin:0 0 10px;overflow: hidden;text-overflow:ellipsis;white-space: nowrap;">${this
            .jdoffice.name}</h2>
          <div style="color:#808080; font-size:16px;">
            <strong>地址：</strong>${this.jdoffice.address} <br>
            <strong>电话：</strong>${this.jdoffice.tell}
          </div>
        </div>`)
      infoWin.setPosition(map.getCenter())
    }
  }
}
</script>
<style lang="scss">
.select_area {
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  position: fixed;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 10000;
  .mask {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
  }
  .wrap {
    background: #fff;
    border-radius: 0.1rem;
    width: 12rem;
    margin: 0.25rem auto;
    padding: 0.55rem;
    text-align: center;
    position: relative;
    z-index: 1200;
    .closed {
      position: absolute;
      right: 0.25rem;
      top: 0.25rem;
    }
    .ht {
      font-size: 0.28rem;
      padding-bottom: 0.2rem;
      color: #555;
    }
    .content {
      display: flex;
      flex-wrap: wrap;
      a {
        width: 33.33%;
        span {
          padding: 0.15rem 0;
          display: block;
          font-size: 0.2rem;
          background: #eee;
          margin: 0 0.1rem 0.1rem 0;
        }
      }
    }
  }
}
.jianDingList-page {
  padding-top: 2.6rem;
}
.jianding-detail {
  background: #fff;
  width: 12.8rem;
  margin: 0 auto 0.8rem;
  padding: 0.5rem;
  border-radius: 0.1rem;
  font-size: 0.18rem;
  .ht {
    display: flex;
    align-items: center;
    font-size: 0.28rem;
    padding: 0.4rem 0 0.2rem;
    img {
      margin-right: 0.1rem;
    }
  }
  .name {
    font-size: 0.42rem;
  }
  .contact {
    border-bottom: 1px dashed #ccc;
    padding: 0.2rem 0;
  }
  .intro {
    p {
      margin-bottom: 0.15rem;
    }
  }
  .ry {
    ul {
      list-style: none;
      margin: 0;
      padding: 0;
      display: flex;
      flex-wrap: wrap;
      li {
        width: 12.5%;
        a {
          display: block;
          margin: 0 0.15rem 0.15rem 0;
          font-size: 0.18rem;
        }
      }
    }
  }
}
#jd-map-container {
  min-height: 3.6rem;
  width: 100%;
  .map-marker-current {
    left: 50%;
    top: 4.6rem;
    position: relative;
    width: 0.5rem;
    height: 0.5rem;
    margin: -0.25rem 0 0 -0.25rem;
    z-index: 10000;
  }
  .map-marker-info {
    // text-align: center;
    // white-space: nowrap;
    margin: 0.1rem;
    h2 {
      font-size: 0.2rem;
      color: #3d69bd;
    }
    div {
      font-size: 0.16rem;
      p {
        margin: 0;
        strong {
          color: #f1543f;
          font-weight: normal;
        }
      }
    }
  }
}
.jianding-list-head {
  padding: 0.25rem 0;
  background: #fff;
  box-shadow: 0 0.1rem 0.1rem rgba(0, 0, 0, 0.05);
  position: fixed;
  top: 1.59rem;
  left: 0;
  right: 0;
  width: 100%;
  .content {
    display: flex;
    align-items: center;
    width: 12.8rem;
    margin: 0 auto;
  }
  h1 {
    font-size: 0.36rem;
    padding: 0 0.3rem 0 0;
    margin: 0;
    font-weight: normal;
  }
  .intro {
    border-left: 1px solid #ddd;
    padding-left: 0.3rem;
    font-size: 0.18rem;
    margin-right: 0.3rem;
    line-height: 1.2;
    p {
      font-size: 0.16rem;
      margin: 0;
      color: #999;
      span {
        color: red;
      }
    }
  }
}
.jianding-list {
  flex: 1;
  .btns {
    padding: 0.3rem 0 1rem;
    border-top: 1px dashed #ccc;
    text-align: center;
    p {
      font-size: 0.18rem;
      color: #666;
    }
  }
  .lists {
    flex: 1;
    width: 12.8rem;
    margin: 0.5rem auto;
    list-style: none;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    .item {
      width: 50%;
      .content {
        border-radius: 0.1rem;
        background: #fff;
        padding: 0.3rem;
        margin: 0 0.25rem 0.25rem 0;
        height: 3rem;
      }
      .name {
        color: #0a57bc;
        font-size: 0.24rem;
        padding-bottom: 0.2rem;
        margin-bottom: 0.2rem;
        border-bottom: 1px dashed #ddd;
        font-weight: bold;
      }
      ul {
        list-style: none;
        padding: 0;
        font-size: 0.16rem;
        li {
          display: flex;
          margin-bottom: 0.15rem;
          color: #666;
          .ct {
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 3;
            overflow: hidden;
          }
          label {
            width: 0.5rem;
            flex-shrink: 0;
            font-weight: bold;
          }
        }
      }
    }
  }
}
@media screen and (orientation: portrait) {
  .select_area {
    width: 90%;
    left: 5%;
    right: 5%;
    top: 3rem;
    align-items: flex-start;
  }
  .jianding-list-head {
    .content {
      width: 90%;
    }
  }
  .jianding-list .lists {
    width: 100%;
    justify-content: space-evenly;
    .item {
      width: 4.85rem;
      .content {
        margin: 0 0 0.2rem;
      }
    }
  }
  .jianding-detail {
    width: 90%;
    margin: 0 auto;
    box-shadow: 0.1rem 0.1rem 0.3rem rgba(0, 0, 0, 0.05);
  }
}
@media screen and (orientation: landscape) {
}
</style>
